# coding:utf-8

import re


# 根据pattern解析文本
class HtmlParser:
    __rules = None

    def __init__(self):
        self.__rules = dict()

    def __del__(self):
        self.__rules = None

    def addrule(self, name, rule):
        pattern = re.compile(rule, re.DOTALL)
        self.__rules[name] = pattern

    def getrule(self, name):
        return self.__rules[name]

    def findall(self, rule_name, html):
        return self.__rules[rule_name].findall(html)
